<template>
  <el-container class="home-container">
    <div class="home-box">
      <el-header>
        <div>
          <div class="inline-block">
            <el-avatar shape="square" :size="50" :src="imageBaseUrl + merchant.icon + '.jpg'" class="icon-box" fit="cover"></el-avatar>
          </div>
          <div class="inline-block">
            <div>
              {{merchant.rnickname}}
            </div>
            <div style="font-size: 25px">
              {{merchant.detail}}
            </div>
          </div>
          <el-button type="warning" icon="el-icon-star-off" circle class="favor" @click="userFavor"></el-button>
        </div>
      </el-header>
      <el-main>
        <el-card>
          <el-menu router mode="horizontal">
            <el-menu-item index="/user/food_list">菜品</el-menu-item>
            <el-menu-item index="/user/other">其他</el-menu-item>
          </el-menu>
          <router-view></router-view>
        </el-card>
      </el-main>
    </div>
  </el-container>
</template>

<script>
export default {
  name: 'RestaurantDetails',
  data () {
    return {
      rid: this.$route.params.rid,
      merchant: {},
      imageBaseUrl: this.$axios.defaults.baseURL + 'static/image/'
    }
  },
  created () {
    this.getMerchant()
  },
  methods: {
    async getMerchant () {
      const rid = { rid: this.rid }
      const { data: res } = await this.$axios.get('/user/restaurant/queryByID', { params: rid })
      if (res.status !== 2000) {
        return this.$message.error('获取商家信息失败')
      }
      this.merchant = res.data.restaurant
      window.sessionStorage.setItem('rid', this.merchant.rid)
      window.sessionStorage.setItem('icon', this.merchant.icon)
      window.sessionStorage.setItem('kpicture', this.merchant.kpicture)
      window.sessionStorage.setItem('cpicture', this.merchant.cpicture)
      await this.$router.push('/user/food_list')
    },
    async userFavor () {
      const p = { uid: window.sessionStorage.getItem('uid'), rid: this.merchant.rid }
      const { data: res } = await this.$axios.post('/user/favorites/add', p)
      if (res.status !== 2000) {
        return this.$message.error('收藏商家失败')
      }
      this.$message.success('收藏成功')
    }
  }
}
</script>

<style scoped>
.home-box {
  width: 1200px;
  left: 50%;
  position: absolute;
  transform: translate(-600px);
  height: 100%;
}
.el-header {
  height: 200px!important;
  padding: 0!important;
}
.el-main {
  padding: 0!important;
}
.icon-box {
  width: 100px !important;
  height: 100px !important;
  margin-left: 30px!important;
  margin-top: 70px!important;
}
.inline-block {
  display: inline-block;
}
.inline-block:nth-child(2) {
  font-size: 45px;
  margin-left: 20px;
}
.favor {
  float: right;
  margin-top: 100px;
}
</style>
